package com.twu.biblioteca.models;

import com.twu.biblioteca.exceptions.BookAlreadyBorrowedError;
import com.twu.biblioteca.exceptions.BookNotBorrowedError;

public class Book {
    public String title;
    public boolean isBorrowed;
    public Integer id;

    protected Book(String aTitle) {
        title = aTitle;
        isBorrowed = false;
    }

    public static Book createWithTitle(String aTitle) {
        return new Book(aTitle);
    }

    public void borrow() throws BookAlreadyBorrowedError {
        if (isBorrowed) {
            throw new BookAlreadyBorrowedError(title);
        }

        isBorrowed = true;
    }

    public void returnMethod() throws BookNotBorrowedError {
        if (!isBorrowed) {
            throw new BookNotBorrowedError(title);
        }
        isBorrowed = false;
    }

    public void print(){
        System.out.println(id + "  |  " + title);
    }
}
